// 歌词时间正则
const parseRep = /\[(\d{2}):(\d{2})\.(\d{2,3})\]/

export function parseLyric(lyricString) {
  const lineString = lyricString.split("\n")
  const lyricList = [] // 歌曲内容和时间

  for (let line of lineString) {
    const result = parseRep.exec(line)
    // console.log(result);
    if (!result) continue
    // 将歌词时长转换为毫秒
    const time1 = result[1] * 60 * 1000 // 歌词分钟
    const time2 = result[2] * 1000 // 歌词秒
    const time3 = result[3].length === 3 ? result[3] * 1 : result[3] * 10 //歌词毫秒
    const time = time1 + time2 + time3
    // console.log(time);
    // 歌词内容
    const content = line.replace(parseRep, '').trim()
    // console.log(content);
    // 歌词对象
    const lineObj = {
      time,
      content
    }
    lyricList.push(lineObj)
  }
  return lyricList
}

